/**
 * 自定义函数
 * */


// 跳转
function toJump(){
    var year_id = $('#year_id').val();
    var month_id = $('#month_id').val();
    var p = '?year_id=' + year_id;
    p += '&month_id=' + month_id;
    window.location.href = 'tu.html' + p;
}


//选项
function getOption(){
    var h = '', i;
    //年份
    // if (year_id == 0) {
    //     h = '<option value="0" selected>选择</option>';
    // } else {
    //     h = '<option value="0">选择</option>';
    // }
    h = '';
    for (i = 1980; i <= 2100; i ++) {
        if (year_id == i) {
            h += '<option value="' + i + '" selected>';
        } else {
            h += '<option value="' + i + '">';
        }
        h += i;
        h += '</option>';
    }
    $('#year_id').html(h);
    //月份
    // if (month_id == 0) {
    //     h = '<option value="0" selected>选择</option>';
    // } else {
    //     h = '<option value="0">选择</option>';
    // }
    h = '';
    for (i = 1; i <= 12; i ++) {
        if (month_id == i) {
            h += '<option value="' + i + '" selected>';
        } else {
            h += '<option value="' + i + '">';
        }
        h += i;
        h += '</option>';
    }
    $('#month_id').html(h);
}


//列表
function getList(){
    var formData = {
        year_id: year_id, month_id: month_id,
    };
    $.ajax({
        type: apiMethod,
        url: apiDomain + 'tongji/tu',
        data: formData,
        success: function (res) {
            console.log(res);
            var h = '', tbody = $('tbody');
            if (res.code < 0) {
                return
            }
            bing(res.data.bing);
            zhu(res.data.zhu);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}
//饼
function bing(d){
    $('#bing').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: '项目的工时占比'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            //data: [
            //    ['Firefox',   45.0],
            //    ['IE',       26.8],
            //    {
            //        name: 'Chrome',
            //        y: 12.8,
            //        sliced: true,
            //        selected: true
            //    },
            //    ['Safari',    8.5],
            //    ['Opera',     6.2],
            //    ['Others',   0.7]
            //]
            data: d
        }]
    });
}
//柱
function zhu(d){
    $('#zhu').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: '个人工时占比'
        },
        subtitle: {
            text: 'Source: WorldClimate.com'
        },
        xAxis: {
            categories: d.title
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Rainfall (%)'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
            '<td style="padding:0"><b>{point.y:.1f} %</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: [{
            name: '个人工时',
            data: d.val
        }]
    });
}